package com.wch.SpringBootTestDemo.dao.impl;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import com.wch.SpringBootTestDemo.dao.UserDao;
import com.wch.SpringBootTestDemo.entity.User;
import com.wch.SpringBootTestDemo.util.MetaClassUtil;

@Service
public class UserDaoImpl implements UserDao{

	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	@Override
	public User getUserInfoByName(String userName){
		// TODO Auto-generated method stub
		String sql = "SELECT PASSWORD,USERNAME,NAME FROM PM_USER A WHERE USERNAME = ?";
		Map<String, Object> userMap = jdbcTemplate.queryForMap(sql, new Object[]{userName});
		User obj = new User();
		//将查询到的map数据转成user对象
		User user = (User) MetaClassUtil.mapToObject(userMap,obj);
		return user;
	}

}
